"""Various path-finding methods
"""

import os
import sys

def inExecutable():
    """Return 'True' if we're running inside py2exe"""
    return  hasattr(sys, "frozen")

def getRootDir():
    """Return path to root ('app') directory"""
    if inExecutable():
        if sys.frozen == "macosx_app":
            _rv = os.path.dirname(os.path.dirname(__file__))
        elif sys.frozen in ("windows_exe", "console_exe"):
            _rv = os.path.dirname(sys.executable)
        else:
            raise NotImplementedError("Implement me for '%s'" % sys.frozen)
    else:
        _rv = os.path.dirname(os.path.dirname(__file__))
    return _rv

def getModuleDir(moduleString):
    """Return path to given module dir.

    Note that `moduleString` should contain only absolute module address.

    """
    _parts = moduleString.split(".")
    assert _parts[0] == "app"
    # last _paert is not needed, since we try to return module dir
    # while path with last part will return module path
    return os.path.join(getRootDir(), *_parts[1:-1])

def getModulePath(moduleString):
    """Return path to given module."""
    _tail = moduleString.rsplit(".", 1)[-1]
    return os.path.join(getModuleDir(moduleString), _tail)

# vim: set sts=4 sw=4 et :
